package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 类名：WebConfigurer.java
 * 路径：com.example.demo.config.WebConfigurer.java
 * 创建人：tanyp
 * 创建时间：2019/12/10 15:23
 * 功能：配置拦截器
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor getSecurityInterceptor() {
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器
        InterceptorRegistration registration = registry.addInterceptor(getSecurityInterceptor());
        // 将这个controller放行
        registration.excludePathPatterns("/error");
        // 拦截全部
        registration.addPathPatterns("/**");
    }
}